package com.b.repository;

import com.b.domain.Dynamic;
import com.b.domain.DynamicComment;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface DynamicRepository extends ElasticsearchRepository<Dynamic,Integer> {
    // 添加查询方法：根据用户ID列表查询动态
    List<Dynamic> findByUserIdIn(List<Integer> userIds);

//    List<DynamicComment> findByDynamicId(Integer dynamicId);

    // 新增动态评论计数更新方法
         default void refreshCommentCount(Integer dynamicId, int increment) {
         Optional<Dynamic> dynamicOpt = findById(dynamicId);
         dynamicOpt.ifPresent(dynamic -> {
             Integer currentCount = dynamic.getCommentCount();
             dynamic.setCommentCount((currentCount == null ? 0 : currentCount) + increment);
             save(dynamic);
         });
     }
}
